#include<iostream>
#include<time.h>
using namespace std;
	int a[20];        //存储随机数1
	int b[20];        //存储随机数2
	int c[21];        //接收随机数之和
	int d[20];        //接收随机数之差
	int f[41];        //接受随机数之积
void Rand(int a[],int b[])    //随机数函数
{
	srand((unsigned)time(NULL));     //随机种子
	int x = rand() % 9 + 1;
	int y = rand() % 9 + 1;
	a[0] = x;
	b[0] = y;
	for (int i = 1; i < 20; i++)    //生成随机数1
	{
		int x = rand() % 10;
		a[i] = x;
	}
	for (int i = 1; i < 20; i++)     //生成随机数2
	{
		int y = rand() % 10;
		b[i] = y;
	}
}
void fun1(int a[], int b[], int c[])//加法函数
{
	int i, j;
	for (i = 0; i < 21; i++)        //初始化数组
	{
		c[i] = 0;
	}
	for (i = 20; i > 0; i--)
	{
		if (a[i - 1] + b[i - 1] + c[i] <= 9)//相加之和小于10，直接相加
		{
			c[i] = a[i - 1] + b[i - 1] + c[i];
		}
		else if (a[i - 1] + b[i - 1] + c[i] > 9)//逢十进一
		{
			c[i] = a[i - 1] + b[i - 1] - 10 + c[i];
			c[i - 1] = c[i - 1] + 1;
		}
	}
	for (i = 0; i < 21; i++)    //输出结果
	{
		for (j = 0; j < 20; j++)
		{
			if (c[j] == 0)      //数组前几位逢0跳过
				continue;
			else
				break;
		}
		if (i >= j)        
			cout << c[i];
	}
    cout << endl;
}
void fun2(int a[], int b[],int d[])//减法
{
	int i, j;
	for (i = 0; i < 20; i++)    //初始化数组
	{
		d[i] = 0;
	}
	for (i = 0; i < 20; i++)    //判断随机数1和随机数2的大小
	{
		if (a[i] > b[i])
		{
			goto flag1;        //a>b，进行a-b
			break;
		}
		if (a[i] < b[i])
		{
			goto flag2;        //a<b，进行b-a
			break;
		}
		if (a[i] == b[i])      //相等则跳过
		{
			continue;
		}
	}
flag1:
	for (i = 19; i >= 0; i--)
	{
		if (a[i] - b[i] + d[i] >= 0)//若相减大于0，直接相减
		{
			d[i] = a[i] - b[i] + d[i];
		}
		else if (a[i] - b[i] + d[i] < 0)//反之，借1
		{
			d[i] = a[i] - b[i] + 10 + d[i];
			d[i - 1] = d[i - 1] - 1;
		}
	}
	for (i = 0; i < 20; i++)     //输出数组
	{
		for (j = 0; j < 20; j++)
		{
			if (d[j] == 0)       //逢0跳过
				continue;
			else
				break;
		}
		if (i >= j)
			cout << d[i];
	}
	goto flag;
flag2:
	for (i = 19; i >= 0; i--)      //同上
	{
		if (b[i] - a[i] + d[i] >= 0)
		{
			d[i] = b[i] - a[i] + d[i];
		}
		else if (b[i] - a[i] + d[i] < 0)
		{
			d[i] = b[i] - a[i] + 10 + d[i];
			d[i - 1] = d[i - 1] - 1;
		}
	}
	cout << "-";
	for (i = 0; i < 20; i++)
	{
		for (j = 0; j < 20; j++)
		{
			if (d[j] == 0)
				continue;
			else
				break;
		}
		if (i >= j)
			cout << d[i];
	}
	goto flag;
flag:cout << endl;
}
void fun3(int a[], int b[], int f[])//乘法
{
	int i, j;
	for (i = 0; i < 41; i++)
	{
		f[i] = 0;        //初始化数组
	}
	for (i = 19; i >= 0; i--)        //这一步是关键
	{
		for (j = 19; j >= 0; j--)
		{
			f[i + j + 2] += a[i] * b[j]; //数组倒着来，最后一位是f[40],对应的是19+19+2
		}                                //以此类推，第f[i+j+2]位就是a[i]*b[j]    
	}
	for (i = 40; i > 0; i--)      //这一步处理数组
	{
		if (f[i] > 9)
		{
			f[i - 1] += f[i] / 10;//每逢十进一
			f[i] %= 10;;          //取模得到结果
		}
	}
	for (i = 0; i < 41; i++)    //输出结果
	{
		for (j = 0; j < 41; j++)
		{
			if (f[j] == 0)
				continue;       //逢0跳过
			else
				break;
		}
		if (i >= j)
			cout << f[i];
	}
}
int main()
{
	Rand(a, b)；        //随机函数调用
	cout << "第一个20位随机大数为：" << endl;
	for (int i = 0; i < 20; i++)
	{
		cout << a[i];
	}
	cout << endl;
	cout << "第二个20位随机大数为：" << endl;
	for (int i = 0; i < 20; i++)
	{
		cout << b[i];
	}
	cout << endl;
	cout << "两个随机大数之和为：" << endl;
	fun1(a, b, c);     //加法函数调用
	cout << "两个随机大数之差为：" << endl;
	fun2(a, b, d);     //减法函数调用
    cout << "两个随机大数之积为：" << endl;
	fun3(a, b, f);     //乘法函数调用
	return 0;
}